package com.evil.log.util;

import com.evil.common.core.util.RedisUtil;
import com.evil.common.core.util.ServletUtils;
import com.evil.common.log.constant.LogConstant;
import com.evil.common.log.util.LogRedisKeyUtil;

import java.util.Optional;

/**
 * @author liyang
 * @date 2023-03-22 09:56
 */
public class LogUtil {

    /**
     * 获取请求日志ID
     * @param redisUtil redisUtil
     * @return String
     */
    public static String getRequestLogId(RedisUtil redisUtil) {
        return Optional.ofNullable(redisUtil.get(LogRedisKeyUtil.requestUuidRequestLogId()))
                .map(e -> (String) e)
                .orElseGet(() -> ServletUtils.getRequest().getHeader(LogConstant.OPERATE_LOG_HEADER));
    }
}
